import java.util.Random;


class PrimeNumberThread extends Thread {
    @Override
    public void run() {
        System.out.println("PrimeNumberThread 开始计算 100 以内的素数");
        for (int i = 2; i <= 100; i++) {
            if (isPrime(i)) {
                System.out.println("PrimeNumberThread: " + i);
            }
        }
        try {
            Random rand = new Random();
            int sleepTime = rand.nextInt(1000); // 生成 0 到 999 毫秒的随机休眠时间
            Thread.sleep(sleepTime);
            System.out.println("PrimeNumberThread 休眠 " + sleepTime + " 毫秒");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


    private boolean isPrime(int num) {
        if (num <= 1) return false;
        for (int i = 2; i * i <= num; i++) {
            if (num % i == 0) return false;
        }
        return true;
    }
}


class DivisibleByThreeThread extends Thread {
    @Override
    public void run() {
        System.out.println("DivisibleByThreeThread 开始计算 100 以内能被 3 整除的数");
        for (int i = 1; i <= 100; i++) {
            if (i % 3 == 0) {
                System.out.println("DivisibleByThreeThread: " + i);
            }
        }
        try {
            Random rand = new Random();
            int sleepTime = rand.nextInt(1000); // 生成 0 到 999 毫秒的随机休眠时间
            Thread.sleep(sleepTime);
            System.out.println("DivisibleByThreeThread 休眠 " + sleepTime + " 毫秒");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}


public class MultiThreadExample {
    public static void main(String[] args) {

        PrimeNumberThread primeThread = new PrimeNumberThread();
        DivisibleByThreeThread divisibleThread = new DivisibleByThreeThread();


        primeThread.start();
        divisibleThread.start();
    }
}
